$(function(){
	//音乐对象
	var player = document.querySelector("audio");
	player.src="video/背景.mp3";
	var musicarr=["video/如来神掌.mp3","video/打狗棍.mp3","video/无影脚.mp3","video/召唤术.mp3"];
	//点击音乐
	$(".music").click(function(){
		if(player.paused==true){
			player.play();
			$(".music").attr("src","img/music-yes.png");
		}else{
			player.pause();
			$(".music").attr("src","img/music-no.png");
		}
	});
	//进度条
	(function(){
		var i=0;
		var timer = setInterval(function(){
			var w = $(".prs").width();
			if(w==243){
				clearInterval(timer);
				$(".box1").removeClass("active");
				$(".box1").hide();
				$(".box2").show();
				$(".box2").addClass("active");
			}
			var n1 = Math.round(w/243*100);
			$(".progressbox p").html(n1+"%");
		},30)
	})();
	
	//点击回到小时候
	$(".btn1").on("click",function(){
		$(".box3").show();
		$(".box2").hide().removeClass("active");
	})
	var arr = ["img/11.jpg","img/37.jpg","img/38.jpg","img/39.jpg"];
	var arr2 = ["img/49.png","img/50.png","img/51.png","img/52.png"];
	var arr3 = ["img/12.png","img/45.png","img/46.png","img/44.png"];
	var arr4 = ["img/13.png","img/40.png","img/41.png","img/42.png"];
	//场景选择
	$('.imglist img').click(function(){
		var idx = $(this).index();
		$(".box3").hide();
		$(".box4").show().addClass("active");
		$(".con1").css("background","url("+arr[$(this).index()]+") 0px 0px/100% 100%");
		$(".chi img").attr("src",arr2[$(this).index()]);
		setTimeout(function(){
			$(".tc").show();
			var i=0;
			var s = 0;
			var i1 = Math.round(Math.random()*4)+30;
			var timer1 = setInterval(function(){
				i++;
				s++;
				if(i==$(".tc-con li").length){
					i=0;
				}
				$(".box5>div").removeClass("active");
				if(s==i1){
					clearInterval(timer1);
					setTimeout(function(){
						$(".tc").hide();
					    $(".box4").removeClass("active").hide();
					    $(".box5").css("background",$(".con1").css("background")).show();
						//i==2是召唤术，i==3是无影脚
						if(i==2){
							$(".box5>div").eq(3).addClass("active");
						}else if(i==3){
							$(".box5>div").eq(2).addClass("active");
						}else{
							$(".box5>div").eq(i).addClass("active");
						}
						$(".box7").show();
						$(".box7 div").eq(idx).addClass("active");
						var a1 = player.paused;
						player.src=musicarr[i];
						if(a1==false){
							player.play();
						}
						setTimeout(function(){
							$(".tc2").show();
							$(".box5").css("background","url("+arr3[i]+") 0px 0px/100% 100%");
							$(".box5 .active").css({"background":"url("+arr4[idx]+") 0px 0px/100% 100%","bottom":"250px"});
							$(".btnbox").css("display","flex");
							$(".box7").hide();
							$(".box7 div").eq(idx).removeClass("active");
						},4000)
					},1000)
				}
				$(".tc-con li").css("filter","brightness(0.8)");
				$(".tc-con li").eq(i).css("filter","brightness(1.5)");
			},100)
		},2000)
	});
	
	//点击我不服
	$(".wbf").click(function(){
		$(".box5").hide();
		$(".tc2").hide();
		$(".btnbox").hide();
		$(".box3").show();
		$(".box5 .active").css({"background":"none","bottom":"150px"});
		var a1 = player.paused;
		player.src="video/背景.mp3";
		if(a1==false){
			player.play();
		}
	})
	//点击我错了
	$(".wcl").click(function(){
		$(".box5").hide();
		$(".tc2").hide();
		$(".btnbox").hide();
		$(".box3").hide();
		$(".box5 .active").css({"background":"none","bottom":"150px"});
		$(".box6").show();
		var a1 = player.paused;
		player.src="video/背景.mp3";
		if(a1==false){
			player.play();
		}
	})
	//点击妈妈再打我一次
	$(".dw").click(function(){
		$(".box6").hide();
		$(".box3").show();
	})
	
})
